<div class="layui-fluid" id="VIEW-list-table" >
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body nepadmin-table-full">
                    <div class="layui-btn-container nepadmin-pad-t10 nepadmin-pad-l10">
                        <div class="layui-btn layui-btn-sm" onclick="scheduleList.add()">添加</div>
                    </div>
                    <table id="scheduleListId" lay-filter="scheduleList"></table>
                </div>
            </div>
        </div>

    </div>
    <script type="text/html" id="TPL-list-table-status">
        {{#
        var status = {
        '1':{title:'暂停',color:'red'},
        '0':{title:'正常',color:'blue'}
        }[d.status];
        }}
        <span class="layui-badge layui-bg-{{status.color}}">{{ status.title }}</span>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="log">日志</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="pause">暂停</a>
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="resume">恢复</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>
<script>
    var scheduleList = {};
    var ScheduleList = function (layui) {
        var admin = layui.admin, table = layui.table, form = layui.form, $ =layui.jquery;
        //初始化列表
        this.init = function () {
            form.render();
            admin.table({
                elem: '#scheduleListId',
                api: 'pageScheduleList',
                height: 'full-140',
                tableFilter:'scheduleList',
                cols: [[
                    {title: '序号', type: 'numbers', fixed: true, width: 60},
                    {title: 'bean名称', field: 'beanName'},
                    {title: '参数', field: 'params'},
                    {title: 'cron表达式', field: 'cronExpression'},
                    {title: '备注', field: 'remark'},
                    {title: '状态', templet: '#TPL-list-table-status', field: 'status'},
                    {title: '操作',fixed: 'right', width: 280, align:'center', toolbar: '#barDemo'}
                ]],
                tools:{
                    log:function (row) {
                        admin.popup({
                            title: row.beanName + '日志',
                            url:'/sys/schedule/log',
                            area: ['80%', '80%'], //宽高
                            data: row,
                            success:function (layer, index) {
                                var logList = new LogList(layui,row.jobId);
                                logList.init();
                            }
                        });
                    },
                    //修改
                    edit:function (row) {
                        admin.popup({
                            type: 3,
                            title:'修改任务',
                            url:'/sys/schedule/edit',
                            area: ['50%', '65%'], //宽高
                            data: row,
                            success:function (layer, index) {
                                var editSchedule = new EditSchedule(admin,form,layer, index,$);
                                editSchedule.init();
                            }
                        });
                    },
                    del:function (row) {
                        admin.confirm("是否删除？",function () {
                            var jobIds = [];
                            jobIds.push(row.jobId);
                            admin.post({
                                api:'deleteSchedule',
                                data:JSON.stringify(jobIds),
                                contentType: 'application/json;charset=UTF-8',
                                success:function (res) {
                                    if(res.code == 0){
                                        admin.success('操作成功',function () {
                                            scheduleList.search();
                                        });
                                    }
                                }
                            });
                        })
                    },
                    pause:function (row) {
                        admin.confirm("确定暂停？",function () {
                            var jobIds = [];
                            jobIds.push(row.jobId);
                            admin.post({
                                api:'pauseSchedule',
                                data:JSON.stringify(jobIds),
                                contentType: 'application/json;charset=UTF-8',
                                success:function (res) {
                                    if(res.code == 0){
                                        admin.success('操作成功',function () {
                                            scheduleList.search();
                                        });
                                    }
                                }
                            });
                        })
                    },
                    resume:function (row) {
                        admin.confirm("确定立刻执行？",function () {
                            var jobIds = [];
                            jobIds.push(row.jobId);
                            admin.post({
                                api:'resumeSchedule',
                                data:JSON.stringify(jobIds),
                                contentType: 'application/json;charset=UTF-8',
                                success:function (res) {
                                    if(res.code == 0){
                                        admin.success('操作成功',function () {
                                            scheduleList.search();
                                        });
                                    }
                                }
                            });
                        })
                    }
                }
            });
        };
        //新增
        this.add = function () {
            admin.popup({
                type: 3,
                title:'新增任务',
                url:'/sys/schedule/add',
                area: ['50%', '65%'], //宽高
                success:function (layer, index) {
                   var addSchedule = new AddSchedule(admin,form,layer, index,$);
                    addSchedule.init();
                }
            });
        };
        //条件搜索
        this.search = function () {
            admin.tableSearch('searchForm','scheduleListId');
        };
        //重置搜索条件
        this.reset = function () {
            $("#key").val("");
        };
    };
    //引入组件
    layui.use(['admin', 'table', 'form', 'jquery'], function () {
        scheduleList = new ScheduleList(layui);
        scheduleList.init();
    });
</script>